﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class TeslimatAdresi : System.Web.UI.Page
{
    protected void Page_PreRender(object sender, EventArgs e)
    {
        DilDegistir();
    }
    protected void DilDegistir()
    {

        if (Cookies.Dil == "TR")
        {
            lblTeslimatAdresi.InnerText = "YENİ TESLİMAT ADRESİ";
            lblAdSoyad.InnerText = "Ad Soyad";
            lblAdres.InnerText = "Adres";
            lblPostaKodu.InnerText = "Posta Kodu";
            lblEPosta.InnerText = "E-Posta";
            lblUlke.InnerText = "Ülke";
            lblSehir.InnerText = "Şehir";
            lblIlce.InnerText = "İlçe";
            lblSemt.InnerText = "Semt";
            lblTelefon.InnerText = "Telefon";
            lblTelefon2.InnerText = "Telefon 2";
            lblHediyeNotu.InnerText = "Hediye notu";

            txtAdSoyad.Attributes["placeholder"] = "Ad Soyad";
            txtSahisAdres.Attributes["placeholder"] = "Adres";
            txtSahisPostaKodu.Attributes["placeholder"] = "Posta Kodu";
            txtEPosta.Attributes["placeholder"] = "E-Posta";
            txtSemt.Attributes["placeholder"] = "Semt";
            txtTelefon.Attributes["placeholder"] = "Telefon";
            txtTelefon2.Attributes["placeholder"] = "Telefon 2";
            txtHediyeNotu.Attributes["placeholder"] = "Hediye notu";

            chkAyniAdres.Text = "Fatura adresimle teslimat adresim aynı olsun. ";
            cbHediye.Text = "Hediye Paketi";
            //btnAdresEkle.Value = "ADRESİ KAYDET VE DEVAM ET";
        }
        else
        {
            lblTeslimatAdresi.InnerText = "NEW DELIVERY ADDRESS";
            lblAdSoyad.InnerText = "Name";
            lblAdres.InnerText = "Address";
            lblPostaKodu.InnerText = "Postal Code";
            lblEPosta.InnerText = "E-Mail";
            lblUlke.InnerText = "Country";
            lblSehir.InnerText = "City";
            lblIlce.InnerText = "County";
            lblSemt.InnerText = "District";
            lblTelefon.InnerText = "Phone";
            lblTelefon2.InnerText = "Phone 2";
            lblHediyeNotu.InnerText = "Gift note";

            txtAdSoyad.Attributes["placeholder"] = "Name";
            txtSahisAdres.Attributes["placeholder"] = "Address";
            txtSahisPostaKodu.Attributes["placeholder"] = "Postal Code";
            txtEPosta.Attributes["placeholder"] = "E-Mail";
            txtSemt.Attributes["placeholder"] = "District";
            txtTelefon.Attributes["placeholder"] = "Phone";
            txtTelefon2.Attributes["placeholder"] = "Phone 2";
            txtHediyeNotu.Attributes["placeholder"] = "Gift note";

            chkAyniAdres.Text = "Invoice and shipping addresses should be same. ";
            cbHediye.Text = "Gift package";
            //btnAdresEkle.Value = "SAVE THE ADDRESS AND CONTINUE";
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //if (Request.UrlReferrer != null)
            //{
                //string prevPage = Request.UrlReferrer.ToString();
                //if (!(prevPage=="" || prevPage.ToLower().Contains("cantam") || prevPage.ToLower().Contains("urun") || prevPage.ToLower().Contains("kategori")))
                    //Response.Redirect(Page.GetRouteUrl("AnaSayfa", new { }));
            //}
            //else
                //Response.Redirect(Page.GetRouteUrl("AnaSayfa", new { }));

            int UrunId = QueryString.Urun;
            int UyeId = Sessions.UyeId;
            int HizliAdet = Sessions.HizliAdet;

            if (UrunId == -1 && UyeId == -1)
                Response.Redirect(Page.GetRouteUrl("AnaSayfa", new { }));

            string dil = "TR";
            if (Request.Cookies["dil"].Value == "ENG")
                dil = "ENG";

            if (Sessions.UyeId > -1)
            {
                txtAdSoyad.Text = Sessions.Ad;
                txtEPosta.Text = Sessions.EPosta;
            }

            DataRow drSiparis = DataAccess.GetSiparisOnaylama(UrunId, HizliAdet, dil);
            Sessions.SiparisFiyati = drSiparis;
        }
    }

    protected void btnKaydet_Click(object sender, EventArgs e)
    {
        int UlkeId = Convert.ToInt16(ulke.SelectedItem.Value);
        int SehirId = Convert.ToInt16(sehir.SelectedItem.Value);
        int IlceId = Convert.ToInt16(ilce.SelectedItem.Value);

        int AdresId = DataAccess.InsAdres(txtAdSoyad.Text, txtSahisAdres.InnerText, txtSahisPostaKodu.Text,txtEPosta.Text, txtFirma.Text, txtVergiDairesi.Text, txtVergiNo.Text, txtAdres.InnerText, txtPostaKodu.Text,
                                UlkeId, SehirId, IlceId, txtSemt.Text, txtTelefon.Text, txtTelefon2.Text);

        Sessions.TeslimatAdresi = AdresId;

        Sessions.SiparisFiyati["HediyePaketi"] = cbHediye.Checked;
        Sessions.SiparisFiyati["HediyeNotu"] = txtHediyeNotu.InnerText;

        if (chkAyniAdres.Checked)
        {
            Sessions.FaturaAdresi = AdresId;
            Response.Redirect(Page.GetRouteUrl("KrediKarti", new { }));
        }
        else
            Response.Redirect(Page.GetRouteUrl("FaturaAdresi", new { }));   

    }
    protected void btnSil_Click(object sender, EventArgs e)
    {
        int AdresId = Convert.ToInt16(hidAdresId.Value);
        DataAccess.DelAdres(AdresId);
        listAdresler.DataBind();
    }

    protected void btnKullan_Click(object sender, EventArgs e)
    {
        Sessions.TeslimatAdresi = Convert.ToInt16(hidAdresId.Value);

        Sessions.SiparisFiyati["HediyePaketi"] = cbHediye.Checked;
        Sessions.SiparisFiyati["HediyeNotu"] = txtHediyeNotu.InnerText;

        Response.Redirect(Page.GetRouteUrl("FaturaAdresi", new { })); 
    }
}